package com.tongji.housediy.view.components
{
	import com.tongji.housediy.utils.TextFieldPool;
	
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class RoomNameContainer extends Sprite
	{
		public function RoomNameContainer()
		{
			super();
		}
		
		public function init(gridContainer:GridContainer):void
		{
			while (this.numChildren > 0)
			{
				TextFieldPool.disposeTextField(this.removeChildAt(0) as TextField);
			}
			
			for (var i:int = 0; i < gridContainer.numChildren; i++)
			{
				if (gridContainer.getChildAt(i) is AbstractDrawingRoom)
				{
					var room:AbstractDrawingRoom = gridContainer.getChildAt(i) as AbstractDrawingRoom;
					var rectangle:Rectangle = room.updateBoundingAndCenterPoint();
					
					var textField:TextField = TextFieldPool.getTextField();
					textField.text = room.roomName;
					
					textField.x = rectangle.x + rectangle.width / 2 - textField.width / 2;
					textField.y = rectangle.y + rectangle.height / 2 - textField.height / 2;
					
					this.addChild(textField);
				}
			}
		}
	}
}